# -*- coding: utf-8 -*-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：encrypt_password.py
#日期：2021-01-28
#备注：数据库数据进行加解密
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

from pycacho.cachobase.base_config import db,cursor,AES_key
from pycacho.cachobase.deal_encrypt import aes_encrypt_ecb,aes_decrypt_ecb

def get_user_info():
    sql = 'select No,password,classify_1 from user_password;'
    cursor.execute(sql)
    results = cursor.fetchall()
    for info in results:
        No = info[0]
        org_str = info[1]
        e_password = aes_encrypt_ecb(org_str,AES_key)    # 加密
        print(No, e_password, info[2])
        #update_user_info(No, e_password)

        d_password = aes_decrypt_ecb(org_str,AES_key)     # 解密
        #print(No,d_password,info[2])


def update_user_info(No,password):
    sql = 'update user_password set password="%s" where No="%s";'%(password,No)
    cursor.execute(sql)
    db.commit()


if __name__ == '__main__':
    get_user_info()
    #update_user_info('11','实时获取验证码登录')

